package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class MousePolice implements MouseListener{

	JTextArea area;
	
	public void setJTextArea(JTextArea area) {
		this.area = area;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getClickCount() >= 2) {
			area.append("\n鼠标进入连击" + "(" + e.getX() + "," + e.getY() + ")");
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		area.append("\n鼠标进入按下" + "(" + e.getX() + "," + e.getY() + ")");
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		area.append("\n鼠标进入释放" + "(" + e.getX() + "," + e.getY() + ")");
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		if (e.getSource()instanceof JButton) {
			area.append("\n鼠标进入按钮" + "(" + e.getX() + "," + e.getY() + ")");
		}
		if (e.getSource()instanceof JTextField) {
			area.append("\n鼠标进入文本框" + "(" + e.getX() + "," + e.getY() + ")");
		}
		if (e.getSource()instanceof JFrame) {
			area.append("\n鼠标进入窗口" + "(" + e.getX() + "," + e.getY() + ")");
		}
	}

	@Override
	public void mouseExited(MouseEvent e) {
		area.append("\n鼠标进入退出" + "(" + e.getX() + "," + e.getY() + ")");
	}

}
